import type {
  KnowledgeParams,
  KnowledgePage,
  PageParams,
  FollowType,
  Image,
  TopDep,
  ConsultOrderPreData,
  ConsultOrderPreParams,
  PartialConsult,
  ConsultOrderItem,
  ConsultOrderListParams,
  ConsultOrderPage,
  DoctorPage,
  MedicinePage,
  MedicineParams,
  MedicineDetail,
  DoctorParams,
  Area,
  Doctor
} from '@/types/consult'

import { request } from '@/utils/request'
/**
 * 获取知识列表
 */
export const getKonwledgeList = (params: KnowledgeParams) => {
  return request<KnowledgePage>('patient/home/knowledge', 'get', params)
}
/**
 * 获取首页推荐关注医生列表
 */
export const getDoctorListApi = (params: PageParams) => {
  return request<DoctorPage>('home/page/doc', 'get', params)
}
/**
 * 获取首页推荐关注医生
 */
export const followOrUnfollow = (id: string, type: FollowType = 'doc') =>
  request('like', 'POST', { id, type })

/**
 * 获取科室
 */
export const getAllDepApi = () => {
  return request<TopDep[]>('dep/all')
}

/**
 * 上传图片
 */
export const uploadImage = (file: File) => {
  const fd = new FormData()
  fd.append('file', file)
  return request<Image>('upload', 'post', fd)
}

/**
 *  拉取预支付订单信息
 */
export const getConsultOrderPre = (params: ConsultOrderPreParams) =>
  request<ConsultOrderPreData>('patient/consult/order/pre', 'GET', params)
/**
 *  生成订单
 */
export const createConsultOrder = (data: PartialConsult) =>
  request<{ id: string }>('patient/consult/order', 'POST', data)

/**
 * 获取支付地址  0 是微信  1 支付宝
 */
export const getConsultOrderPayUrl = (params: {
  paymentMethod: 0 | 1
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('patient/consult/pay', 'POST', params)

/**
 * 获取订单详情
 */
export const getConsultOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('patient/consult/order/detail', 'GET', { orderId })

/**
 * 获取处方地址
 */
export const getPrescriptionPic = (id: string) =>
  request<{ url: string }>(`patient/consult/prescription/${id}`)

// 评价问诊
export const evaluateConsultOrder = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 0 | 1
}) => request<{ id: string }>('/patient/order/evaluate', 'POST', data)
/**
 * 获取问诊订单列表
 */
export const getConsultOrderList = (params: ConsultOrderListParams) =>
  request<ConsultOrderPage>('/patient/consult/order/list', 'GET', params)

/**
 * 取消订单
 */
export const cancelOrder = (id: string) => request(`/patient/order/cancel/${id}`, 'PUT')
/**
 * 删除订单
 */
export const deleteOrder = (id: string) => request(`/patient/order/${id}`, 'DELETE')

/**
 * 获取选择药品 - 药品列表
 */
export const getMedicinePage = (params: MedicineParams) => {
  return request<MedicinePage>('patient/medicine', 'GET', params)
}

/**
 * 选择药品详情
 */
export const getMedicineDetail = (id: string) => {
  return request<MedicineDetail>(`patient/medicine/${id}`)
}

/**
 *
 * @param params
 * @returns  问医生-搜索医生列表
 */
export const getFindDoctorPage = (params: DoctorParams) => {
  return request<DoctorPage>('/patient/search/doc', 'GET', params)
}

/**
 *
 * @returns 获取所有省市区
 */
export const getAllBasicArea = () => {
  return request<Area[]>('basicArea/all')
}
/**
 *
 * @returns 获取医生详情
 */
export const getDoctorDetail = (id: string) => {
  return request<Doctor>(`doc/detail`, 'GET', {
    docId: id
  })
}
